<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>TYPE</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.2 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Embedded SQL Commands"
HREF="ecpg-sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="SET DESCRIPTOR"
HREF="ecpg-sql-set-descriptor.html"><LINK
REL="NEXT"
TITLE="VAR"
HREF="ecpg-sql-var.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2011-12-01T22:07:59"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.2 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="SET DESCRIPTOR"
HREF="ecpg-sql-set-descriptor.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="ecpg-sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="VAR"
HREF="ecpg-sql-var.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="ECPG-SQL-TYPE"
></A
>TYPE</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN43568"
></A
><H2
>Name</H2
>TYPE&nbsp;--&nbsp;define a new data type</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN43571"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>TYPE <TT
CLASS="REPLACEABLE"
><I
>type_name</I
></TT
> IS <TT
CLASS="REPLACEABLE"
><I
>ctype</I
></TT
></PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43575"
></A
><H2
>Description</H2
><P
>     The <TT
CLASS="COMMAND"
>TYPE</TT
> command defines a new C type.  It is
     equivalent to putting a <TT
CLASS="LITERAL"
>typedef</TT
> into a declare
     section.
    </P
><P
>     This command is only recognized when <TT
CLASS="COMMAND"
>ecpg</TT
> is
     run with the <TT
CLASS="OPTION"
>-c</TT
> option.
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43583"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>type_name</I
></TT
></DT
><DD
><P
>        The name for the new type.  It must be a valid C type name.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>ctype</I
></TT
></DT
><DD
><P
>        A C type specification.
       </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43596"
></A
><H2
>Examples</H2
><PRE
CLASS="PROGRAMLISTING"
>EXEC SQL TYPE customer IS
    struct
    {
        varchar name[50];
        int     phone;
    };

EXEC SQL TYPE cust_ind IS
    struct ind
    {
        short   name_ind;
        short   phone_ind;
    };

EXEC SQL TYPE c IS char reference;
EXEC SQL TYPE ind IS union { int integer; short smallint; };
EXEC SQL TYPE intarray IS int[AMOUNT];
EXEC SQL TYPE str IS varchar[BUFFERSIZ];
EXEC SQL TYPE string IS char[11];</PRE
><P
>     Here is an example program that uses <TT
CLASS="COMMAND"
>EXEC SQL
     TYPE</TT
>:
</P><PRE
CLASS="PROGRAMLISTING"
>EXEC SQL WHENEVER SQLERROR SQLPRINT;

EXEC SQL TYPE tt IS
    struct
    {
        varchar v[256];
        int     i;
    };

EXEC SQL TYPE tt_ind IS
    struct ind {
        short   v_ind;
        short   i_ind;
    };

int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
    tt t;
    tt_ind t_ind;
EXEC SQL END DECLARE SECTION;

    EXEC SQL CONNECT TO testdb AS con1;

    EXEC SQL SELECT current_database(), 256 INTO :t:t_ind LIMIT 1;

    printf("t.v = %s\n", t.v.arr);
    printf("t.i = %d\n", t.i);

    printf("t_ind.v_ind = %d\n", t_ind.v_ind);
    printf("t_ind.i_ind = %d\n", t_ind.i_ind);

    EXEC SQL DISCONNECT con1;

    return 0;
}</PRE
><P>

     The output from this program looks like this:
</P><PRE
CLASS="SCREEN"
>t.v = testdb
t.i = 256
t_ind.v_ind = 0
t_ind.i_ind = 0</PRE
><P>
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43603"
></A
><H2
>Compatibility</H2
><P
>     The <TT
CLASS="COMMAND"
>TYPE</TT
> command is a PostgreSQL extension.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="ecpg-sql-set-descriptor.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="ecpg-sql-var.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>SET DESCRIPTOR</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecpg-sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>VAR</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>